import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);

	public Integer pop();

	public Integer peek();

	public boolean empty();

	public int size();
}

class ArrayIntegerStack implements IntegerStack {

	Integer[] stack;
	private int top;

	public ArrayIntegerStack(int n) {
		stack = new Integer[n];
		top = 0;
	}

	public Integer push(Integer item) {
		if (item == null)
			return null;
		if (top == stack.length)
			return null;
		stack[top++] = item;
		return item;

	}

	public Integer pop() {
		if (top == 0)
			return null;
		return stack[--top];
	}

	public Integer peek() {
		if (top == 0)
			return null;
		return stack[top - 1];
	}

	public boolean empty() {
		if (top == 0)
			return true;
		return false;
	}

	public int size() {
		return top;
	}

}

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in 

 

);
		int n = in.nextInt();
		ArrayIntegerStack a = new ArrayIntegerStack(n);
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(a.push(in.nextInt()));
		}
		System.out.println(a.peek() + "," + a.empty() + "," + a.size());
		System.out.println(Arrays.toString(a.stack));
		int x = in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(a.pop());
		}
		System.out.println(a.peek() + "," + a.empty() + "," + a.size());
		System.out.println(Arrays.toString(a.stack));
	}

}